﻿// -----------------------------------------------------------------------
// <copyright file="CustomTabControl.cs" company="Abyssalsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Gui.ControlBuilders
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Xml;
    using Metal.Resources;
    using Gui.ThemeEngine;
    
    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class CustomTabControl : BaseControl
    {
        /// <summary>
        /// Create the custom control
        /// </summary>
        /// <param name="controlProperties">The Xml node that contains the control properties</param>
        /// <returns>Returns custom control</returns>
        public Controls.TabControl.MetalTabControl GetControl(XmlNode controlProperties)
        {
            // Get tab alignment
            string strAlignment = PropertyProvider.GetValue(controlProperties, "tabAlignment", "Top");

            Controls.TabControl.MetalTabControl customTabControl = new Controls.TabControl.MetalTabControl(strAlignment);

            // Apply common properties
            this.BuildControl(controlProperties, customTabControl as Control);

            // Apply specific control properties
            int intPageCounter = 0;

            // Add tab pages
            foreach (XmlNode page in controlProperties.ChildNodes)
            {
                if (PropertyProvider.GetValue(page, "type", string.Empty) == "TabPage")
                {
                    string strTabCaption = MessageProvider.GetMessage(PropertyProvider.GetValue(page, "resourceID", string.Empty));
                    customTabControl.TabPages.Add(strTabCaption);
                    customTabControl.TabPages[intPageCounter].BackColor = PropertyProvider.GetValue(page, "backColor");

                    // Store in our TabControl the UserControl class name that we must to load in this page (will be loaded on tab click)
                    string containerURI = PropertyProvider.GetValue(page, "maskNamespace", string.Empty) + ";" + PropertyProvider.GetValue(page, "className", string.Empty);
                    customTabControl.TabbedMasks.Add(containerURI);
                }

                intPageCounter++;
            }

            // Apply style
            string strStyleName = PropertyProvider.GetValue(controlProperties, "anchor", "Default");

            switch (strStyleName)
            {
                case "Default":
                    customTabControl.DisplayStyle = Controls.TabControl.TabStyle.VS2010;
                    break;
                case "Angled":
                    customTabControl.DisplayStyle = Controls.TabControl.TabStyle.Angled;
                    break;
                case "Chrome":
                    customTabControl.DisplayStyle = Controls.TabControl.TabStyle.Chrome;
                    break;
                case "IE8":
                    customTabControl.DisplayStyle = Controls.TabControl.TabStyle.IE8;
                    break;
                case "Rounded":
                    customTabControl.DisplayStyle = Controls.TabControl.TabStyle.Rounded;
                    break;
            }

            customTabControl.DisplayStyleProvider.CloserColorActive = PropertyProvider.GetValue(controlProperties, "closerColorActive");
            customTabControl.DisplayStyleProvider.CloserColor = PropertyProvider.GetValue(controlProperties, "closerColor");
            customTabControl.DisplayStyleProvider.TextColor = PropertyProvider.GetValue(controlProperties, "textColor");
            customTabControl.DisplayStyleProvider.TextColorSelected = PropertyProvider.GetValue(controlProperties, "textColorSelected");
            customTabControl.DisplayStyleProvider.BorderColorHot = PropertyProvider.GetValue(controlProperties, "borderColorHot");
            customTabControl.DisplayStyleProvider.SelectedTabColor = PropertyProvider.GetValue(controlProperties, "selectedTabColor");
            customTabControl.DisplayStyleProvider.SelectedTabColor2 = PropertyProvider.GetValue(controlProperties, "selectedTabColor2");
            customTabControl.DisplayStyleProvider.HotTrackingColor = PropertyProvider.GetValue(controlProperties, "hotTrackingColor");
            customTabControl.DisplayStyleProvider.BorderColorSelected = PropertyProvider.GetValue(controlProperties, "tabPageBorderColor");
            customTabControl.DisplayStyleProvider.FocusColor = Color.Black;

            return customTabControl;
        }

        /// <summary>
        /// Apply common properties
        /// </summary>
        /// <param name="control">The Xml node that contains our control properties</param>
        /// <param name="customControl">The custom control that will be created</param>
        public override void BuildControl(System.Xml.XmlNode control, System.Windows.Forms.Control customControl)
        {
            base.BuildControl(control, customControl);
        }
    }
}
